from django.contrib.auth import get_user_model
from rest_framework import serializers
from .models import *

User = get_user_model()


class PatientSerializer(serializers.ModelSerializer):
    gender_label = serializers.CharField(source='get_gender_display', read_only=True)

    class Meta:
        model = Patient
        fields = '__all__'
        read_only_fields = ('create_time', 'update_time', 'is_delete')


class BatchSerializer(serializers.ModelSerializer):
    school_label = serializers.StringRelatedField(source='school')
    hospital_label = serializers.StringRelatedField(source='hospital')

    class Meta:
        model = Batch
        fields = '__all__'
        read_only_fields = ('number', 'create_time', 'update_time', 'is_delete')


class ReportSerializer(serializers.ModelSerializer):
    school_name = serializers.StringRelatedField(source='batch.school', read_only=True)
    hospital_name = serializers.StringRelatedField(source='batch.hospital', read_only=True)
    report_type_label = serializers.CharField(source='get_report_type_display', read_only=True)
    patient_name = serializers.StringRelatedField(source='patient', read_only=True)
    doctor_name = serializers.CharField(source='doctor.name', read_only=True)
    patient_info = PatientSerializer(source='patient', read_only=True)
    creator = serializers.HiddenField(default=serializers.CurrentUserDefault())

    class Meta:
        model = Report
        fields = '__all__'
        read_only_fields = ('number', 'create_time', 'update_time', 'is_delete')


class CheckResultSerializer(serializers.ModelSerializer):
    class Meta:
        model = CheckResult
        fields = '__all__'
        read_only_fields = ('create_time', 'update_time')
